﻿@using System.Collections.Generic
@using JuCheap.Core.Models
@using JuCheap.Core.Infrastructure.Enums
@using JuCheap.Core.Infrastructure.Extentions
@{
    List<MenuDto> menus = ViewBag.Menus;
}

<nav class="navbar-default navbar-static-side" role="navigation">
    <div class="nav-close">
        <i class="fa fa-times-circle"></i>
    </div>
    <div class="sidebar-collapse">
        <ul class="nav" id="side-menu">
            <li class="nav-header">
                <div class="dropdown profile-element">
                    <h1 style="font-size: 2em; color: white; text-align: center">JuCheap</h1>
                </div>
                <div class="logo-element">
                    Ju3
                </div>
            </li>
            @if (menus != null)
            {
                @*一级目录开始*@
                foreach (var module in menus.OrderBy(x => x.Order).Where(item => item.Type == MenuType.Module))
                {
                    <li>
                        <a href="#">
                            <i class="@(module.Icon.IsBlank() ? "fa fa-tv" : module.Icon)"></i>
                            <span class="nav-label">@module.Name</span>
                            <span class="fa arrow"></span>
                        </a>
                        <ul class="nav nav-second-level">
                            @*二级目录开始*@
                            @foreach (var menu in menus.OrderBy(x => x.Order).Where(item => item.ParentId == module.Id))
                            {
                                var hasThirdMenu = menus.Any(x => x.ParentId == menu.Id);
                                @if (hasThirdMenu)
                                {
                                    <li>                                    
                                        <a href="#">
                                            <i class="@(menu.Icon.IsBlank() ? "fa fa-angle-right" : menu.Icon)"></i>
                                            @menu.Name
                                        </a>

                                        @*三级目录开始*@
                                        @if(hasThirdMenu)
                                        {
                                            <ul class="nav nav-third-level collapse">

                                            @foreach(var thirdMenu in menus.OrderBy(x => x.Order).Where(x => x.ParentId == menu.Id))
                                            {
                                                <li>
                                                    <a class="J_menuItem" href="@thirdMenu.Url" data-index="@thirdMenu.Id">
                                                        <i class="@(thirdMenu.Icon.IsBlank() ? "fa fa-angle-right" : thirdMenu.Icon)"></i>
                                                        @thirdMenu.Name
                                                    </a>
                                                </li>
                                            }

                                            </ul>
                                        }
                                    </li>
                                }
                                else
                                {
                                    <li>                                    
                                        <a class="J_menuItem" href="@menu.Url" data-index="@module.Id">
                                            <i class="@(menu.Icon.IsBlank() ? "fa fa-angle-right" : menu.Icon)"></i>
                                            @menu.Name
                                        </a>
                                    </li>
                                }
                            }
                        </ul>

                    </li>
                }
            }
        </ul>
    </div>
    <div class="sidebar-footer">
        <a id="btnChangeMenu"><span class="fa fa-reorder"></span></a>
        <a class="hidden-small"><span class="fa fa-desktop"></span></a>
        <a class="hidden-small"><span class="fa fa-lock"></span></a>
        <a class="hidden-small" asp-controller="User" asp-action="Add"><span class="fa fa-power-off"></span></a>
    </div>
</nav>
